/**
*      author: Y_Yao
*      created: 2025-04-19 20:06:49
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 3e5 + 7;
int n,m;
int b[N];
unordered_map<int,int> mp;
vector<int> a[N];
int mx[N];
int L[N];
int ans[N];

void solve()
{
    cin >> n >> m;
    for(int i = 1;i <= m;i++)
    {
        cin >> L[i];
        for(int j = 1;j <= L[i];j++)
        {
            int x;
            cin >> x;
            a[i].push_back(x);
        }
    }
    for(int i = 1;i <= n;i++)
    {
        cin >> b[i];
        mp[b[i]] = i;//cai to tian
    }
    for(int i = 1;i <= m;i++)
    {
        for(int j = 0;j < L[i];j++)
        {
            mx[i] = max(mp[a[i][j]],mx[i]);
        }
        // cout << mx[i] << " ";
    }
    // cout << endl;

    for(int i = 1;i <= m;i++)
    {
        ans[mx[i]]++;
    }
    int cur = 0;
    for(int i = 1; i <= n;i++)
    {
        cur += ans[i];
        cout << cur << endl;
    }

}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}